package io.scnb.lesson001.demo24.test4;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        // 定义一个bean：Service1
        AbstractBeanDefinition service1BeanDefinition = BeanDefinitionBuilder.genericBeanDefinition(Service1.class).getBeanDefinition();

        // 注册bean
        registry.registerBeanDefinition("service1", service1BeanDefinition);

        // 定义一个bean：Service2
        AbstractBeanDefinition service2BeanDefinition = BeanDefinitionBuilder.genericBeanDefinition(Service2.class).getBeanDefinition();
        // 注册bean
        registry.registerBeanDefinition("service2", service2BeanDefinition);
    }
}
